-bin_SCRIPTS += hacktree
+noinst_LTLIBRARIES += libhacktree.la
-SUBSTITUTIONS = sed -e s,@libdir\@,$(libdir), -e s,@datarootdir\@,$(datarootdir), -e s,@PYTHON\@,$(PYTHON),
+libhacktree_la_SOURCES = src/hacktree.h \
+ src/hacktree-repo.c \
+ src/hacktree-repo.h \
+ src/hacktree-types.h \
+ $(NULL)
+libhacktree_la_CFLAGS = -I$(srcdir)/src -DLOCALEDIR=\"$(datadir)/locale\" $(GIO_UNIX_CFLAGS)
+libhacktree_la_LIBADD = $(GIO_UNIX_LIBS)
-hacktree: src/hacktree.in Makefile
- $(AM_V_GEN) $(SUBSTITUTIONS) $< > $@.tmp && mv $@.tmp $@
- @chmod a+x $@
+bin_PROGRAMS += hacktree
-CLEANFILES += hacktree
+hacktree_SOURCES = src/main.c \
+ src/ht-builtins.h \
+ src/ht-builtin-init.c \
+ $(NULL)
+hacktree_CFLAGS = -I$(srcdir)/src -DLOCALEDIR=\"$(datadir)/locale\" $(GIO_UNIX_CFLAGS)
+hacktree_LDADD = libhacktree.la $(GIO_UNIX_LIBS)
BUILT_SOURCES =
CLEANFILES =
EXTRA_DIST =
+bin_PROGRAMS =
bin_SCRIPTS =
libexec_PROGRAMS =
noinst_LTLIBRARIES =
--- /dev/null
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2011 Colin Walters <walters@verbum.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Author: Colin Walters <walters@verbum.org>
+ */
+
+#include "config.h"
+
+#include "hacktree-repo.h"
+
+enum {
+ PROP_0,
+
+ PROP_PATH
+};
+
+G_DEFINE_TYPE (HacktreeRepo, hacktree_repo, G_TYPE_OBJECT)
+
+#define GET_PRIVATE(o) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((o), HACKTREE_TYPE_REPO, HacktreeRepoPrivate))
+
+typedef struct _HacktreeRepoPrivate HacktreeRepoPrivate;
+
+struct _HacktreeRepoPrivate {
+ char *path;
+};
+
+static void
+hacktree_repo_finalize (GObject *object)
+{
+ G_OBJECT_CLASS (hacktree_repo_parent_class)->finalize (object);
+}
+
+static void
+hacktree_repo_set_property(GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ HacktreeRepo *self = HACKTREE_REPO (object);
+ HacktreeRepoPrivate *priv = GET_PRIVATE (self);
+
+ switch (prop_id)
+ {
+ case PROP_PATH:
+ priv->path = g_value_dup_string (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+hacktree_repo_get_property(GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ HacktreeRepo *self = HACKTREE_REPO (object);
+ HacktreeRepoPrivate *priv = GET_PRIVATE (self);
+
+ switch (prop_id)
+ {
+ case PROP_PATH:
+ g_value_set_string (value, priv->path);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+hacktree_repo_class_init (HacktreeRepoClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (HacktreeRepoPrivate));
+
+ object_class->finalize = hacktree_repo_finalize;
+
+ g_object_class_install_property (object_class,
+ PROP_PATH,
+ g_param_spec_string ("path",
+ "",
+ "",
+ NULL,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+}
+
+static void
+hacktree_repo_init (HacktreeRepo *self)
+{
+}
+
+HacktreeRepo*
+hacktree_repo_new (const char *path)
+{
+ return g_object_new (HACKTREE_TYPE_REPO, "path", path, NULL);
+}
+
+gboolean
+hacktree_repo_import (HacktreeRepo *repo,
+ const char *path)
+{
+
+}
--- /dev/null
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2011 Colin Walters <walters@verbum.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Author: Colin Walters <walters@verbum.org>
+ */
+/* hacktree-repo.h */
+
+#ifndef _HACKTREE_REPO
+#define _HACKTREE_REPO
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define HACKTREE_TYPE_REPO hacktree_repo_get_type()
+#define HACKTREE_REPO(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), HACKTREE_TYPE_REPO, HacktreeRepo))
+#define HACKTREE_REPO_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), HACKTREE_TYPE_REPO, HacktreeRepoClass))
+#define HACKTREE_IS_REPO(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), HACKTREE_TYPE_REPO))
+#define HACKTREE_IS_REPO_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), HACKTREE_TYPE_REPO))
+#define HACKTREE_REPO_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), HACKTREE_TYPE_REPO, HacktreeRepoClass))
+
+typedef struct {
+ GObject parent;
+} HacktreeRepo;
+
+typedef struct {
+ GObjectClass parent_class;
+} HacktreeRepoClass;
+
+GType hacktree_repo_get_type (void);
+
+HacktreeRepo* hacktree_repo_new (const char *path);
+
+gboolean hacktree_repo_import (HacktreeRepo *repo,
+ const char *path);
+
+G_END_DECLS
+
+#endif /* _HACKTREE_REPO */
--- /dev/null
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2011 Colin Walters <walters@verbum.org>.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Author: Colin Walters <walters@verbum.org>
+ */
+
+#ifndef __HACKTREE_TYPES_H__
+#define __HACKTREE_TYPES_H__
+
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+#define HACKTREE_REPO_DIR ".ht"
+
+G_END_DECLS
+
+#endif
--- /dev/null
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2011 Colin Walters <walters@verbum.org>.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Author: Colin Walters <walters@verbum.org>
+ */
+
+#ifndef __HACKTREE_H__
+
+#include <hacktree-repo.h>
+#include <hacktree-types.h>
+
+#endif
+++ /dev/null
-#!@PYTHON@
-# -*- Mode: Python -*-
-# Copyright (C) 2011 Colin Walters <walters@verbum.org>
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301, USA.
-#
-
-import os
-import sys
-import re
-
-import __builtin__
-
-__builtin__.__dict__['DATADIR'] = "@datarootdir@"
-
-path = os.path.join('@libdir@', 'hacktree')
-sys.path.insert(0, path)
-
--- /dev/null
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2011 Colin Walters <walters@verbum.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Author: Colin Walters <walters@verbum.org>
+ */
+
+#include "config.h"
+
+#include "ht-builtins.h"
+#include "hacktree.h"
+
+#include <glib/gi18n.h>
+
+static char *repo_path;
+static GOptionEntry options[] = {
+ { "repo", 0, 0, G_OPTION_ARG_FILENAME, &repo_path, "Repository path", NULL },
+ { NULL }
+};
+
+gboolean
+hacktree_builtin_init (int argc, const char **argv, const char *prefix, GError **error)
+{
+ gboolean ret = FALSE;
+ char *htdir_path = NULL;
+ char *objects_path = NULL;
+ GFile *htdir = NULL;
+ GFile *objects_dir = NULL;
+
+ if (repo_path == NULL)
+ repo_path = ".";
+
+ htdir_path = g_build_filename (repo_path, HACKTREE_REPO_DIR, NULL);
+ htdir = g_file_new_for_path (htdir_path);
+
+ if (!g_file_make_directory (htdir, NULL, error))
+ goto out;
+
+ objects_path = g_build_filename (htdir_path, "objects", NULL);
+ objects_dir = g_file_new_for_path (objects_path);
+ if (!g_file_make_directory (objects_dir, NULL, error))
+ goto out;
+
+ ret = TRUE;
+ out:
+ g_free (htdir_path);
+ g_clear_object (&htdir);
+ return ret;
+}
--- /dev/null
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2011 Colin Walters <walters@verbum.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Author: Colin Walters <walters@verbum.org>
+ */
+
+#ifndef __HACKTREE_BUILTINS__
+#define __HACKTREE_BUILTINS__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+typedef enum {
+ HACKTREE_BUILTIN_FLAG_NONE = 0,
+} HacktreeBuiltinFlags;
+
+typedef struct {
+ const char *name;
+ gboolean (*fn) (int argc, const char **argv, const char *prefix, GError **error);
+ int flags; /* HacktreeBuiltinFlags */
+} HacktreeBuiltin;
+
+gboolean hacktree_builtin_init (int argc, const char **argv, const char *prefix, GError **error);
+
+G_END_DECLS
+
+#endif
--- /dev/null
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2011 Colin Walters <walters@verbum.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Author: Colin Walters <walters@verbum.org>
+ */
+
+#include "config.h"
+
+#include <glib-unix.h>
+#include <gio/gio.h>
+
+#include <string.h>
+
+#include "ht-builtins.h"
+
+static HacktreeBuiltin builtins[] = {
+ { "init", hacktree_builtin_init, 0 },
+ { NULL }
+};
+
+static int
+usage (char **argv, gboolean is_error)
+{
+ HacktreeBuiltin *builtin = builtins;
+ void (*print_func) (const gchar *format, ...);
+
+ if (is_error)
+ print_func = g_printerr;
+ else
+ print_func = g_print;
+
+ print_func ("usage: %s COMMAND [options]\n",
+ argv[0]);
+ print_func ("Builtin commands:\n");
+
+ while (builtin->name)
+ {
+ print_func (" %s\n", builtin->name);
+ builtin++;
+ }
+ return (is_error ? 1 : 0);
+}
+
+
+int
+main (int argc,
+ char **argv)
+{
+ HacktreeBuiltin *builtin;
+ const char *cmd;
+
+ g_type_init ();
+
+ builtin = builtins;
+
+ if (argc < 2)
+ return usage (argv, 1);
+
+ cmd = argv[1];
+
+ while (builtin->name)
+ {
+ GError *error = NULL;
+ if (strcmp (cmd, builtin->name) == 0)
+ {
+ if (!builtin->fn (argc - 2, (const char**)argv + 2, NULL, &error))
+ {
+ g_printerr ("%s\n", error->message);
+ g_clear_error (&error);
+ return 1;
+ }
+ return 0;
+ }
+ builtin++;
+ }
+
+ g_printerr ("Unknown command '%s'\n", cmd);
+ return usage (argv, 1);
+}